import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:loading_overlay/loading_overlay.dart';

/// todo: 基础脚手架
baseScaffoldWidget({Widget? child,bool loading:false,OnRefreshCallback? onRefresh,OnLoadCallback? onLoad}){
  // Header浮动
  bool _headerFloat = false;
  // 震动
  bool _vibration = true;
  return LoadingOverlay(
    isLoading: loading,
    color: Colors.black,
    opacity: 0.35,
    progressIndicator: Center(
      child: ClipRRect(
        borderRadius: BorderRadius.circular(15),
        child: Container(
          width: 120,
          height: 120,
          color: Colors.black,
          padding: EdgeInsets.all(20),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 48,
                height: 48,
                child: CircularProgressIndicator(color: Colors.green,strokeWidth: 5.5,),
              ),
              Text("请稍后",style: TextStyle(color: Colors.white,fontSize: 16,),),
            ],
          ),
        ),
      ),
    ),
    child: EasyRefresh(
      header: ClassicalHeader(
        enableInfiniteRefresh: false,
        infoColor: _headerFloat ? Colors.black87 : Colors.teal,
        textColor: Colors.teal,
        float: _headerFloat,
        enableHapticFeedback: _vibration,
        refreshText: "拉动刷新",
        refreshReadyText: "释放刷新",
        refreshingText: "正在刷新...",
        refreshedText: "刷新完成",
        refreshFailedText: "刷新失败",
        noMoreText: "没有更多数据",
        infoText: "更新于 %T",
      ),
      footer: MaterialFooter(
        enableInfiniteLoad: false,
      ),
      // footer:ClassicalFooter(
      //   enableInfiniteLoad: false,
      //   enableHapticFeedback: _vibration,
      //   loadText: "拉动加载",
      //   loadReadyText: "释放加载",
      //   loadingText: "正在加载...",
      //   loadedText: "加载完成",
      //   loadFailedText: "加载失败",
      //   noMoreText: "没有更多数据",
      //   infoText: "",
      //   textColor: Colors.transparent,
      // ),
      onRefresh: onRefresh ?? null,
      onLoad: onLoad ?? null,
      child: child,
    ),
  );
}

/// todo: 基础脚手架2
baseWidget1(Widget child,{required bool loading,OnRefreshCallback? onRefresh,OnLoadCallback? onLoad}){
  return LoadingOverlay(
    isLoading: loading,
    child: EasyRefresh(
      header: MaterialHeader(),
      footer: MaterialFooter(),
      onRefresh: onRefresh ?? null,
      onLoad: onLoad ?? null,
      child: child,
    ),
  );
}

/// todo: 基础loading
baseLoadingOverlay({Widget? child,bool loading:false}){
  return  LoadingOverlay(
    isLoading: loading,
    color: Colors.black,
    opacity: 0.35,
    progressIndicator: Center(
      child: ClipRRect(
        borderRadius: BorderRadius.circular(15),
        child: Container(
          width: 120,
          height: 120,
          color: Colors.black,
          padding: EdgeInsets.all(20),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox( width: 48, height: 48, child: CircularProgressIndicator(color: Colors.green,strokeWidth: 5.5,),),
              Text("请稍后",style: TextStyle(color: Colors.white,fontSize: 16,),),
            ],
          ),
        ),
      ),
    ),
    child: child ?? SizedBox(),
  );
}


